package com.googlecode.FWT.view.buttons.print
{
	import com.googlecode.FWT.core.NotificationNames;
	import com.googlecode.FWT.model.ProjectDataProxy;
	import com.googlecode.FWT.view.buttons.back.ButtonMediator;
	
	import flash.events.MouseEvent;
	
	import org.puremvc.as3.interfaces.INotification;

	/**
	 * Integrates the ClearButton view component with the PureMVC framework. 
	 * @author ~martin
	 * 
	 */
	public class PrintButtonMediator extends ButtonMediator
	{
		
		/**
		 * PureMVC identifier. 
		 */
		public static const NAME:String = "PrintButtonMediator";
		
		/**
		 * Constructor 
		 * @param viewComponent
		 * 
		 */
		public function PrintButtonMediator(viewComponent:PrintButton)
		{
			super(NAME, viewComponent);
		}
		
		/**
		 * PureMVC callback - the mediator has been registered with the framework.
		 * Carries out framework-dependent initialisation code. 
		 */
		override public function onRegister():void
		{
			super.onRegister();
			
			// make sure the clear is invisible
			viewRef.visible = false;
		}
		
		/**
		 * Notify interest in page change events. 
		 * @return 
		 * 
		 */
		override public function listNotificationInterests():Array
		{
			var list:Array = super.listNotificationInterests();
			list.push(ProjectDataProxy.PAGE_INDEX_CHANGED);
			
			return list;
		}
		
		/**
		 * When a paged is changed, the clear button needs to be made invisible, if not on the activity page. 
		 * @param notification
		 * 
		 */
		override public function handleNotification(notification:INotification):void
		{
			// if the button is on the first page, make it invisible
			if(notification.getBody() as int == 2)
			{
				viewRef.visible = true;
			}else
			{
				viewRef.visible = false;
			}
		}
		/**
		 * Sends notification that clear button has been clicked. 
		 * @param evt
		 * 
		 */
		override protected function onButtonClick(evt:MouseEvent):void
		{
			sendNotification(NotificationNames.PRINT);
		}
		
	}
}